﻿#region Copyright Clause
/*
 * Blue Marble Genesis Smart Client Framework
 * 
 * Copyright © 2009 Blue Marble. All rights reserved.
 * 
 * This code is protected from any unauthorized duplication or viewing under
 * international copyright laws. Unauthorized access to this code is prosecutable
 * under the full extent of the law.
 */
#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace Genesis.Client.Host.Commands.Common
{
    [Genesis.Common.Attributes.CommandCode("Common.WebBrowser.Show")]
    [Genesis.Common.Attributes.CommandDescription("This command shows the web browser")]
    [Genesis.Common.Attributes.CommandName("Web Browser")]
    public class ShowWebBrowser : Genesis.Common.Classes.CommandBase, Genesis.Common.Interfaces.ICommand
    {
        #region ICommand Members

        void Genesis.Common.Interfaces.ICommand.Execute()
        {
            Genesis.Client.Common.Forms.WebBrowser webBrowser = new Genesis.Client.Common.Forms.WebBrowser();

            webBrowser.Host = this.host;

            bool hasUrl = false;

            for (int i = 0; i < this.parameters.Count; i++)
            {
                webBrowser.PageProperties.Add(new Genesis.Common.Classes.PageProperty(parameters[i].Name, parameters[i].Value));

                if (this.parameters[i].Name == "Url")
                {
                    hasUrl = true;
                }
            }

            if (!hasUrl)
            {
                webBrowser.PageProperties.Add(new Genesis.Common.Classes.PageProperty("Url", "http://localhost:1652/genesis.web/default.aspx?SessionGuid=" + this.host.GlobalDataSetFunctions.GetActiveSessionGuid().ToString()));
            }

            webBrowser.Navigate();

            base.host.CreateWindow(webBrowser);
        }

        #endregion
    }
}
